package com.ck.controller.teacher;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.ck.domain.Chapter;
import com.ck.domain.Panduan;
import com.ck.service.QuestionService;

public class ShowPanduanInfoController extends AbstractController {
	
	private QuestionService questionService;
	
	public void setQuestionService(QuestionService questionService) {
		this.questionService = questionService;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		Integer panduanID = Integer.parseInt(request.getParameter("panduanID"));
		Panduan panduan = questionService.gainPanduan(panduanID);
		
		Chapter chapter = questionService.gainChapter(panduan.getChapter());
		String chapter_name = chapter.getName();
		String subject_name = questionService.gainSubject(chapter.getSubject()).getName();
		
		String pic_url = null;
		if(panduan.getPic()!=null){
			pic_url = questionService.showImage(request, panduan.getPic());
		}
		
		Map model = new HashMap();
		model.put("panduan", panduan);
		model.put("chapter_name", chapter_name);
		model.put("subject_name", subject_name);
		model.put("pic_url", pic_url);
		
		return new ModelAndView("teacher/showPanduanInfo", model);
	}

}
